<template>
    <div class="tableList">
        <el-table :data="tableData" border style="width: 100%;"
            :header-cell-style="{background:'#fafafa',color:'#000',fontWeight:400,fontSize:'12px'}"
            :cell-style="{color:'#5a5a5a',fontSize:'12px',fontWeight:400}" v-loading="loading"
            element-loading-text="加载中" element-loading-background="rgba(250, 250, 250, 0.5)"
            element-loading-spinner="el-icon-loading" ref="tabList">
            <el-table-column label="序号" width="80">
                <template slot-scope="scope">
                    <span>{{(searchForm.page - 1) * (searchForm.limit) + scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="deviceSn" label="设备" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="date" label="日期" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="lampColorName" label="亮灯" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="exceptionReason" label="异常原因" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="startTime" label="开始时间" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="durationHour" label="时长(小时)" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="endTime" label="结束时间" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="workOrderCode" label="工单号" show-overflow-tooltip width="180">
            </el-table-column>
            <el-table-column prop="productCode" label="产品编号" show-overflow-tooltip width="180">
            </el-table-column>
            <div slot="empty">
                <el-empty :image-size="100"></el-empty>
            </div>
        </el-table>
        <el-pagination v-if="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :page-sizes="[10,20,50,100]" :page-size="searchForm.limit" layout="total,prev, pager, next,sizes"
            :total="total" background>
        </el-pagination>
    </div>
</template>

<script>
    import {
        exceptionList
    } from '@/api/exceptionController'
    export default {
        data() {
            return {
                tableData: [],
                loading: false,
                total: 0
            }
        },
        props: {
            searchForm: {
                type: Object,
                default: () => ({})
            }
        },
        methods: {
            //异常报表列表
            getExceptionList(data) {
                this.loading = true
                exceptionList(data).then(res => {
                    if (res.code == 200) {
                        this.tableData = res.data
                        this.total = res.count
                    }
                    this.loading = false
                })
            },
            //pageSize 改变时会触发
            handleSizeChange(val) {
                this.searchForm.limit = val
                this.getExceptionList(this.searchForm)
            },
            //currentPage 改变时会触发
            handleCurrentChange(val) {
                this.searchForm.page = val
                this.getExceptionList(this.searchForm)
            },
        },
    }
</script>

<style lang="less" scoped>
    .tableList {
        code {
            font-family: sans-serif;
        }
    }
</style>